package cn.itsource.ymcc.mq;

import cn.itsource.ymcc.constants.BaseConstants;
import cn.itsource.ymcc.service.ICourseCartService;
import io.netty.util.CharsetUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RocketMQMessageListener(topic = BaseConstants.Cart.TOPIC_CART_2REDIS,
        selectorExpression=BaseConstants.Cart.TAGS_CART_2REDIS
        ,consumerGroup = "service-cart-consumer"
        ,messageModel = MessageModel.CLUSTERING
    )
public class Cart2RedisConsumer implements RocketMQListener<MessageExt> {

    @Autowired
    private ICourseCartService courseCartService;

    @Override
    public void onMessage(MessageExt message) {
        String msg = new String(message.getBody(), CharsetUtil.UTF_8);
        log.info("Cart2RedisConsumer 消费者, {} ",msg);
        Long userId = Long.valueOf(msg);
        //加载用户的购物车数据到Redis
        //courseCartService.loadCourseForUser(userId);
    }
}
